home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / pages.js < prev    next >
Encoding:
Text File  |  2007-07-09  |  4.0 KB  |  131 lines

  1. var PFFTempPagesObject = new XML();
  2. var pffDebugTempPagesObject = [];
  3.  
  4. performancingUtil.prototype.loadPagesXMLFile = function(){
  5.     var pagesFileInfo = gPerformancingUtil.getPagesXMLFileInfo();
  6.     var pagesFile = PerFormancingFileIO.open(pagesFileInfo.path);
  7.     var theXMLString = null;
  8.     
  9.     if(pagesFile.exists()){
  10.         theXMLString = PerFormancingFileIO.read(pagesFileInfo, "UTF-8");
  11.         var theXML = new XML(theXMLString);
  12.         return theXML;
  13.     }
  14.     else {
  15.         // File doesn't exist.
  16.         return false;
  17.     }
  18. }
  19.  
  20. performancingUtil.prototype.getPagesXMLFileInfo = function(){
  21.     var file = PerFormancingDirIO.get("ProfD");
  22.     file.append("extensions");
  23.     file.append('performancing-pages.xml');
  24.     return file;
  25. }
  26.  
  27. performancingUtil.prototype.addPageToEditor = function (theElement) {
  28.     var thePostID = theElement.getAttribute("postid");
  29.     var theDateCreated = theElement.getAttribute("date");
  30.     var pagesFile = gPerformancingUtil.loadPagesXMLFile();
  31.  
  32.     var theBlogXML = new XML(pagesFile);
  33.     pffDebugTempPagesObject = theBlogXML;
  34.     
  35.     try {
  36.         var theEntry = theBlogXML..entry.(postid == thePostID);
  37.  
  38.         // Now load everything
  39.         // First Focus the Source
  40.         var tabbox = document.getElementById("performancing-editor-tabbox"); 
  41.  
  42.         //convert back to html
  43.         var theContent = theEntry.content.toString();
  44.         theContent = theContent.replace(/</gi, "<");
  45.         theContent = theContent.replace(/>/gi, ">");
  46.  
  47.         // Then Load the contents
  48.  
  49.         if (tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){
  50.             // Rich or preview
  51.             var winNormal = document.getElementById("performancing-message");
  52.             winNormal.contentWindow.document.body.innerHTML = theContent;
  53.         }
  54.         else if(tabbox.selectedIndex == 1){
  55.             // Source
  56.             document.getElementById("performancing-message-source").value = theContent;
  57.         }
  58.         else{
  59.             alert("Could not load page data.");
  60.         }
  61.         
  62.         var winPreview = document.getElementById("performancing-preview-display");
  63.         document.getElementById("performancing-message-source").value = theContent;
  64.         performancingMidas.syncNormalTab();
  65.  
  66.         //Then Load the Title
  67.         var theTitle = theEntry.title.toString();
  68.         document.getElementById("performancing-editor-subject").value = theTitle;
  69.  
  70.         //Show Republish button and set attributes
  71.         var editButtons = document.getElementById("post-edit-buttons");
  72.         var pubButton = document.getElementById("performancing-republish-button");
  73.         pubButton.setAttribute("lastpostid", thePostID);
  74.         pubButton.setAttribute("datecreated", theDateCreated);
  75.         editButtons.hidden = false;
  76.         
  77.         return true;
  78.     } catch(e) {
  79.         return true;
  80.     }
  81. }
  82.  
  83. performancingUtil.prototype.clearPagesXMLFile = function(){
  84.     var fileInfo = gPerformancingUtil.getPagesXMLFileInfo();
  85.     var file = PerFormancingFileIO.open(fileInfo.path);
  86.     
  87.     var theXMLFile = null;
  88.     var theBlogXML = <pagelist><list></list></pagelist>;;
  89.     PFFTempHistoryObject = theBlogXML;
  90.     
  91.     // Doesn't exist, so let's create it.
  92.     if (!file.exists()){
  93.         PerFormancingFileIO.create(file);
  94.     }
  95.     else {
  96.         PerFormancingFileIO.open(file.path);
  97.     }
  98.     
  99.     var rv = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  100.     
  101.     if(!rv) {
  102.         var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  103.     }
  104. }
  105.  
  106. performancingUtil.prototype.setPagesXML = function(thePostID, theContent, theTitle, theCategories, theDateCreated){
  107.     PFFTempHistoryObject.list.entry += <entry><postid>{thePostID}</postid><content>{theContent}</content><title>{theTitle}</title><categories>{theCategories}</categories><datecreated>{theDateCreated}</datecreated></entry>;
  108. }
  109.  
  110. performancingUtil.prototype.savePagesXMLFile = function(){
  111.     var fileInfo = gPerformancingUtil.getPagesXMLFileInfo();
  112.     var file = PerFormancingFileIO.open(fileInfo.path);
  113.     
  114.     if(file.exists()){
  115.         var theXMLFile = PerFormancingFileIO.open(file.path);
  116.         
  117.         // Write to file (save changes)
  118.         var newWrite = PerFormancingFileIO.write(file, PFFTempHistoryObject.toString(), "w", "UTF-8");
  119.         PFFTempHistoryObject = null;
  120.         
  121.         if(!newWrite) {
  122.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  123.         }
  124.         
  125.         return true;
  126.     }
  127.     else{
  128.         return false;
  129.     }
  130. }
  131.